Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

feat(Feature/GoogleAnalytics): Implemented Optout link feature for GA… #231

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

bdbch
Copy link
Contributor

@bdbch bdbch commented Jun 26, 2017

… optout links

@bdbch bdbch self-assigned this Jun 26, 2017
@bdbch bdbch requested a review from dgrdl June 26, 2017 09:50
"translatableOptions": [
{
"name": "optOutConfirm",
"label": "Optout Confirm Text",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opt out is two words

"label": "Optout Confirm Text",
"type": "text",
"required": 1,
"default_value": "Are you sure you want to opted out of Google Analytics?"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opt out, remove the -ed

},
{
"name": "optOutSuccess",
"label": "Optout Success Text",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opt out

"label": "Optout Success Text",
"type": "text",
"required": 1,
"default_value": "You successfully opted out from Google Analytics for this website."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opted out of Google Analytics

@@ -2,18 +2,43 @@

namespace Flynt\Features\GoogleAnalytics;

define(__NAMESPACE__ . '\NS', __NAMESPACE__ . '\\');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used, unless I'm missing something?

'confirm' => (isset($googleAnalyticsOptionsTranslatable['optOutConfirm'])) ? $googleAnalyticsOptionsTranslatable['optOutConfirm'] : '',
'success' => (isset($googleAnalyticsOptionsTranslatable['optOutSuccess'])) ? $googleAnalyticsOptionsTranslatable['optOutSuccess'] : ''
];
wp_localize_script('Flynt/Features/GoogleAnalytics', 'wpData', $data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this global variable wpData could lead to issues, especially since the same name is used in this feature here:

wp_localize_script('Flynt/Features/AdminComponentPreview', 'wpData', $data);

We should prefix this to make sure nothing can go wrong (for example flynt_feature_google_analytics). The same should be done in the feature mentioned above in a separate PR.

setOptoutCookie()
}
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like having two separate scripts (this file and the script.twig file) loaded in the same feature for no apparent reason. Either this functionality should be moved or the existing script should be extracted into this file. Defining and passing the same variables twice using two different approaches makes little sense.

Also it needs to be noted that the order in which these two scripts load is of importance. In this case it works fine, because this file is loaded first. But if that changed for some reason, it's not obvious that the opt out would not work anymore (since the ga() call would be triggered before the window variable is set).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep it seperated since the script.twig is really only for the Google Analytics script tag and doesn't really have own logic in there. Also the GoogleAnalytics.php passes down some anonymizeIP functionality into the script.twig view.

import $ from 'jquery'
import 'file-loader?name=vendor/js-cookie.js!js-cookie/src/js.cookie'

const $gaOptoutLinks = $('.globalAction-optoutGa')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like a class is too restrictive for this. What if I wanted to do the opt out programmatically instead? This approach would not allow for that. Also, further down you remove all opt out "links", not giving anyone the choice to maybe use a button for example that could be set to disabled instead.

Why not just have a function available here that can be called in a component and let the component handle the visual counterpart (click event, removing the element or toggling a class)?

package.json Outdated
@@ -78,7 +78,9 @@
"postbump": "gulp replaceVersion && git add ."
}
},
"dependencies": {},
"dependencies": {
"js-cookie": "^2.1.4"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this dependency to devDependencies

$data = [
'gaId' => $googleAnalyticsOptions['gaId'],
'confirm' => (isset($googleAnalyticsOptionsTranslatable['optOutConfirm'])) ? $googleAnalyticsOptionsTranslatable['optOutConfirm'] : '',
'success' => (isset($googleAnalyticsOptionsTranslatable['optOutSuccess'])) ? $googleAnalyticsOptionsTranslatable['optOutSuccess'] : ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • these variables are quite wordy and could be shortened
  • instead of doing an isset and passing an empty string here, you should just pass the value and check it in the script if it's false before you run the alert (and maybe not run an empty alert in that case, which is weird). Same goes for the confirm box of course.

@bdbch
Copy link
Contributor Author

bdbch commented Jun 29, 2017

@Qakulukiam this PR is also updated. If you still want (me) to refactor, just add notes on what I could do to improve this feature.

@dgrdl
Copy link
Contributor

dgrdl commented Jul 18, 2017

Could you tell me how this feature addition would be used? (And please also add it to the readme.)

Because as far as I can see, it is not going to work since the window variable is only set after the confirm popup. Then a cookie is set, but that cookie doesn't do anything. For more info on what actually disables Google Analytics, check this link.

Please also test this with a real GA account after your adjustments, just to double-check.

@bdbch
Copy link
Contributor Author

bdbch commented Aug 22, 2017

@Qakulukiam you're right. definitely needs more testing to see where to actually modify the GA optout value.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants